package cn.com.pagoda.ideplugin.listener;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * 加密/解密页面密钥输入框鼠标监听器
 * @Author xieluxin
 * @Date 2023/7/9 17:11
 * @Version 1.0
 */
public class KeyFieldMouseListener implements MouseListener {

    private final JTextField keyField;
    public KeyFieldMouseListener(JTextField keyField){
        this.keyField = keyField;
    }

    /**
     * Invoked when the mouse button has been clicked (pressed
     * and released) on a component.
     *
     * @param e the event to be processed
     */
    @Override
    public void mouseClicked(MouseEvent e) {
        if(keyField.getText().equals("请输入密钥:")){
            keyField.setText("");
        }
    }

    /**
     * Invoked when a mouse button has been pressed on a component.
     *
     * @param e the event to be processed
     */
    @Override
    public void mousePressed(MouseEvent e) {

    }

    /**
     * Invoked when a mouse button has been released on a component.
     *
     * @param e the event to be processed
     */
    @Override
    public void mouseReleased(MouseEvent e) {
        if(keyField.getText() == null || keyField.getText().equals("")){
            keyField.setText("请输入密钥:");
        }
    }

    /**
     * Invoked when the mouse enters a component.
     *
     * @param e the event to be processed
     */
    @Override
    public void mouseEntered(MouseEvent e) {

    }

    /**
     * Invoked when the mouse exits a component.
     *
     * @param e the event to be processed
     */
    @Override
    public void mouseExited(MouseEvent e) {
    }
}